package com.xingxuecn.demos.mybatis.mapper;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * 这个容器放置了一个SqlSessionFactory对象
 * 由于整个项目只需要一个SqlSessionFactory
 * @author Kris at 2018/9/20 17:02
 */
public class SqlSessionFactoryContainer {

    private static SqlSessionFactory sqlSessionFactory;

    public static SqlSessionFactory getSqlSessionFactory() {
        if(sqlSessionFactory == null){
            InputStream inputStream = SqlSessionFactory.class.getClassLoader().getResourceAsStream("mybatis-config.xml");
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        }
        return sqlSessionFactory;
    }
}
